package com.shinektv.utils;

import android.text.TextUtils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Description: <ToastUtil><br>
 * Author: mxdl<br>
 * Date: 2018/6/11<br>
 * Version: V1.0.0<br>
 * Update: <br>
 */
public class InfoVerify {
    /**
     * 校验邮箱
     * @param paramString
     * @return
     */
    public static boolean isValidEmail(String paramString) {

        String regex = "[a-zA-Z0-9_\\.]{1,}@(([a-zA-z0-9]-*){1,}\\.){1,3}[a-zA-z\\-]{1,}";
        if (paramString.matches(regex)) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * 校验ＱＱ
     * @param paramString
     * @return
     */
    public static boolean isValidQQ(String paramString) {
        String regex = "^[1-9](\\d){4,9}$";
        if (paramString.matches(regex)) {
            return true;
        }
        return false;
    }

    /**
     * 校验车牌号
     * @param paramString
     * @return
     */
    public static boolean isValidPlatnum(String paramString) {
        if (TextUtils.isEmpty(paramString)) return false;
        String regex = "^[\u4e00-\u9fa5]{1}[A-Z_a-z]{1}[A-Z_0-9_a-z]{5}$";
        if (paramString.matches(regex)) {
            return true;
        }
        return false;
    }

    /**
     * 校验手机号
     * @param paramString
     * @return
     */
    public static boolean isValidMobiNumber(String paramString) {
        // String regex = "^((13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$";
        if (paramString == null) return false;
        String regex = "^1\\d{10}$";
        if (paramString.matches(regex)) {
            return true;
        }
        return false;
    }

    /**
     * 该方法有问题...
     * @param str
     * @return
     */
    public static boolean isNumeric(String str) {
        Pattern pattern = Pattern.compile("^[0-9]+\\.?[0-9]*[0-9]$");
        Matcher isNum = pattern.matcher(str);
        return isNum.matches();
    }

    public static boolean isIntegerNumric(String str) {
        Pattern pattern = Pattern.compile("^\\d+$");
        Matcher isNum = pattern.matcher(str);
        return isNum.matches();
    }

    public static boolean isDecimalNumric(String str) {
        Pattern pattern = Pattern.compile("^-?\\d+(\\.\\d+)?$");
        Matcher isNum = pattern.matcher(str);
        return isNum.matches();
    }

    /**
     * 是否是IP
     * @param text
     * @return
     */
    public static boolean ipV4Check(String text) {
        if (text != null && !text.isEmpty()) {
            // 定义正则表达式
            String regex = "^(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|[1-9])\\." +
                    "(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\." +
                    "(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\." +
                    "(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)$";
            // 判断ip地址是否与正则表达式匹配
            if (text.matches(regex)) {
                // 返回判断信息
                return true;
            } else {
                // 返回判断信息
                return false;
            }
        }
        return false;
    }

    /**
     * 端口是否合法
     * @param text 端口
     * @return
     */
    public static boolean checkPort(String text) {
        boolean isLegal = false;

        String regex = "^([1-9][0-9]{0,3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])" +
                "(?::([0-9]{1,4}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5]))?$";
        isLegal = text.matches(regex);
        return isLegal;
    }

    /**
     * 是否是数字0-9
     * @param str
     * @return
     */
    public static boolean isNumeric09(String str) {
        Pattern pattern = Pattern.compile("[0-9]*");
        Matcher isNum = pattern.matcher(str);
        return isNum.matches();
    }
}